package com.esun.payment_api.service.impl;

import com.esun.payment_api.bean.InvContentImportBean;
import com.esun.payment_api.domain.TExcelTableCol;
import com.esun.payment_api.mapper.TExcelTableColMapper;
import com.esun.payment_api.service.TExcelTableColService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TExcelTableColServiceImpl implements TExcelTableColService {

    @Resource
    JdbcTemplate jdbcTemplate;

    @Resource
    TExcelTableColMapper tExcelTableColMapper;

    @Override
    public List<TExcelTableCol> getParamByTableName(String tableName) {
        return tExcelTableColMapper.getParamByTableName(tableName);
    }

    @Override
    public void importContentFromMidTable(InvContentImportBean importParam) {
        String sql = "insert into inv_form_content (inv_id,tax_rate,co_id,create_by,content_code,content,production,model,unit,num,price,money,remarks,group_no) " +
                "select " + importParam.getInvId() +
                "," + importParam.getTaxRate() +
                "," + importParam.getCoId() +
                "," + importParam.getUserId() +
                ",c1,c2,c3,c4,c5,c6,c7,c8,c9,c10 from sys_import_data where collection_name='xcx_kpnr'";
        jdbcTemplate.update(sql);
        String delSql = "delete from sys_import_data where collection_name='xcx_kpnr'";
        jdbcTemplate.update(delSql);
    }
}
